﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

namespace Identity.Models;

public class Role: IdentityRole
{
    /// <summary>
    /// 获得/设置 角色主键ID
    /// </summary>
    public override string Id { get; set; }=new Guid().ToString();

    /// <summary>
    /// 获得/设置 角色名称
    /// </summary>
    [DisplayName("角色名称")]
    [NotNull]
    public override string?  Name { get; set; }

    /// <summary>
    /// 获得/设置 角色描述
    /// </summary>
    [DisplayName("角色描述")]
    [NotNull]
    public  string? Description { get; set; }

    [InverseProperty("Role")]
    public virtual ICollection<NavigationRole> NavigationRoles { get; set; } = new List<NavigationRole>();

 
    public ICollection<UserRole> UserRoles { get; set; } = new List<UserRole>();

    /// <summary>
    /// 只读属性：通过 UserRoles 访问用户
    /// </summary>
    [NotMapped] // 标记为不在数据库中映射
    public ICollection<User> Users => UserRoles.Select(ur => ur.User).ToList();

}




